package com.zj.dubbo.handler;

import com.zj.dubbo.RpcRunTimeException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author zhaojin
 */
@Slf4j
@Aspect
@Component
public class RpcRuntimeExceptionHandler {
    @AfterThrowing(throwing = "exception", pointcut = "execution(* com.zj.dubbo.user.service.*.*(..))")
    public void afterThrow(Throwable exception) {
        if (exception instanceof RuntimeException) {
            log.error("RpcRunTimeException side->exception occured: {}", exception.getMessage(),
                    exception);
            throw new RpcRunTimeException(exception);
        }
    }
}
